package com.hui.util;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.apache.commons.lang.StringUtils;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class CommonHelper {
    public static Gson gson = new Gson();

    public static String toJson(Object obj) {
        return gson.toJson(obj);
    }

    private static Map<?, ?> getMap(String params) {
        return gson.fromJson(params, new TypeToken<Map<?, ?>>() {
        }.getType());
    }

    private static List<?> getList(String params) {
        return gson.fromJson(params, new TypeToken<List<?>>() {
        }.getType());
    }
    public static Map<?, ?> getMapByText(String params) {
        LinkedHashMap paramMap = new LinkedHashMap();
        if (StringUtils.isNotBlank(params)) {
            try {
                paramMap = new LinkedHashMap(getMap(params));
            } catch (Exception var3) {
                paramMap = new LinkedHashMap();
            }
        }

        if (paramMap == null) {
            paramMap = new LinkedHashMap();
        }

        return paramMap;
    }
}
